package com.aaa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.aaa.util.HttpUtils;

@WebServlet("/taobao")
public class TaobaoServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		Map<String, String> headers = new HashMap<>();

		headers.put("Referer", "https://www.taobao.com/");

		HttpResponse get = null;
		try {
			get = HttpUtils.doGet(
					"https://tui.taobao.com/recommend?appid=2493&_ksTS=1589342367489_786&callback=jsonp787", "", "GET",
					headers, null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		String taobaoData = EntityUtils.toString(get.getEntity());

		resp.setContentType("text/json;charset=UTF-8");
		PrintWriter out = resp.getWriter();

		out.write(taobaoData);
		out.close();

	}

}
